#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lsg_filebucket.h"
#include "lsg_log.h"

using namespace LSG;

int main(int argc, char * argv[])
{
    if(argc != 2)
    {
	printf("test_filebucket content\n");
	return -1;
    }

    lsg_set_log_path("./log");

    CFileBucket filebucket("./0", 1024, 8, 4);

    if(filebucket.Error()) {
	printf("init fail: %s\n", filebucket.ErrMsg());
	return -1;
    }

    char physic_id[32] = {0};
    int buddybit_offset = filebucket.Save(physic_id, argv[1], strlen(argv[1]), 0);
    if(buddybit_offset < 0) {
	printf("Save fail: %d\n", buddybit_offset);
	return -1;
    }

    char *data = NULL;
    int data_len = 0;
    int e = filebucket.Read(physic_id, &data, &data_len, NULL);
    printf("Read %s: %s[%d]\n", physic_id, data, e);

    return 0;
}
